package Hash;

import java.util.HashSet;
import java.util.Set;

public class IsHappy202 {
    public boolean isHappy(int n) {
        Set<Integer> set = new HashSet<>();
        while (n != 1 && !set.contains(n)) {
            set.add(n);
            int res = 0;
            while (n > 0) {
                int temp = n % 10;
                res += (int) Math.pow(temp,2);
                n = n / 10;
            }
            n = res;
        }

        return n==1;
    }
}
